package com.example.shw.twocache

import android.app.Activity
import android.graphics.BlurMaskFilter
import android.graphics.Color
import android.graphics.EmbossMaskFilter
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.DisplayMetrics
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.widget.LinearLayout
import com.example.shw.R

class TwoCacheActivity : AppCompatActivity(){
    private lateinit var emboss : EmbossMaskFilter
    private lateinit var blur : BlurMaskFilter
    private lateinit var drawView : DrawViewTwo

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val line = LinearLayout(this)
        val displayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getRealMetrics(displayMetrics)
        drawView = DrawViewTwo(this, displayMetrics.widthPixels, displayMetrics.heightPixels)
        line.addView(drawView)
        setContentView(line)
        emboss = EmbossMaskFilter(floatArrayOf(1.5f, 1.5f, 1.5f), 0.6f, 0f, 4.2f)
        blur = BlurMaskFilter(8f, BlurMaskFilter.Blur.NORMAL)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        val inflator = MenuInflater(this)
        inflator.inflate(R.menu.menu_twocache, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId)
        {
            R.id.red -> {
                drawView.paint.color = Color.RED
                item.isChecked = true
            }
            R.id.green -> {
                drawView.paint.color = Color.GREEN
                item.isChecked = true
            }
            R.id.blue -> {
                drawView.paint.color = Color.BLUE
                item.isChecked = true
            }
            R.id.width_1 -> drawView.paint.strokeWidth = 1f
            R.id.width_3 -> drawView.paint.strokeWidth = 3f
            R.id.width_5 -> drawView.paint.strokeWidth = 5f
            R.id.blur -> drawView.paint.maskFilter = blur
            R.id.emboss -> drawView.paint.maskFilter = emboss
        }
        return true
    }
}